package com.red.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.red.entity.ProductType;
import com.red.result.Result;
import com.red.service.ProductTypeService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product/type")
public class ProductTypeController {
    @Autowired
    private ProductTypeService productTypeService;

    @ApiOperation("根据条件查询商品分类")
    @ApiImplicitParam(name = "name",value = "分类名称")
    @GetMapping("/select")
    public Result findAll(String name){
        return new Result(
                productTypeService.list(
                        new QueryWrapper<ProductType>()
                                .like(name!=null,"name",name)
                )
        );
    }

    @ApiOperation("添加商品分类")
    @PostMapping("/save")
    public Result save(ProductType productType){
        return new Result(productTypeService.save(productType));
    }

    @ApiOperation("修改商品分类")
    @PutMapping("/update")
    public Result update(ProductType productType){
        return new Result(productTypeService.updateById(productType));
    }

    @ApiOperation("删除商品分类")
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        return  new Result(productTypeService.removeById(id));
    }
}
